package com.sync.utils.framework.config;

import com.sync.utils.framework.interceptor.HeaderParamsCheckInterceptor;
import com.sync.utils.framework.interceptor.SignValidateInterceptor;
import com.sync.utils.framework.interceptor.TokenInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * TODO
 *
 * @Author YWF
 * @Date 2022/1/24 17:52
 */

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    private final static Logger logger = LoggerFactory.getLogger(InterceptorConfig.class);

    private final static String pathPatterns = "/*/**";

    private static final String[] excludePathPatterns  = {"/**/user/login","/**/user/vLogin"};

    @Override
    public void addInterceptors(InterceptorRegistry registry){
        //请求头参数校验
        //registry.addInterceptor(signAndHeaderParamsCheckInterceptor());
        //token校验
        //registry.addInterceptor(tokenInterceptor()).addPathPatterns(pathPatterns)
        //        .excludePathPatterns(excludePathPatterns);
    }

    @Bean
    public TokenInterceptor tokenInterceptor(){
        return new TokenInterceptor();
    }

    @Bean
    public SignValidateInterceptor signAndHeaderParamsCheckInterceptor(){
        return new SignValidateInterceptor();
    }

}
